<script setup>
import useUserStore from '@/store/modules/user'
import useSetStore from '@/store/modules/set'
import { checkPermi, checkRole } from "@/utils/permission"
import { getToken } from '@/utils/auth';
import { onMounted, ref } from 'vue';
import { licationTime } from '@/utils/config.js'
import { timeFormat } from 'uview-plus'
import { onShow, onReady, onHide } from '@dcloudio/uni-app';

// #ifdef WEB
	 // setTimeout(() => {
		//  console.log(111111111)
		//  var geolocation = new BMapGL.Geolocation()
		//  geolocation.getCurrentPosition( function (r) {
		// 	 console.log(r)
		//  })
	 // }, 1000)
// #endif

const setStore = useSetStore()
const tyUrl = uni.getStorageSync('tyUrl')
if (tyUrl) {
	setStore.setBaseUrl(tyUrl)
}
const userStore = useUserStore()
onHide(() => {
	// #ifdef APP-PLUS
	// startForegroundService()
	// #endif
})
onShow(() => {
	// #ifdef APP-PLUS
	// stopForegroundService()
	// #endif
})

onMounted(async() => {
	const token = getToken()
	setStore.getEnv()
	// setStore.setAppLogo()
	// setStore.setAppName()
	setStore.clearTimer()
	setStore.clearOrderTimer()
	if (token) {
		await setStore.getAllProvinceList()
		await userStore.getInfo()
		await userStore.getUserProfile()
		// 打卡定位
		if (checkPermi(['zhouyz:salesmanPath:add']) && !checkRole(['admin'])) {
			setStore.setTimer(userStore.user.userId)
		}
		// 订单查询
		if (checkPermi(['	zhouyz:order:list'])) {
			setStore.setOrderTimer(userStore.user.userId)
		}
	} else {
		uni.redirectTo({
			url: '/pages/login'
		})
	}
})
</script>

<style lang="scss">
@import "uview-plus/index.scss";
@import '@/static/scss/index.scss';
</style>